import { CalendarPicker, InfiniteScroll, List, NavBar } from "antd-mobile";
import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { baoApi } from "../../api";
import axios from "../../utils/index";
import { Cell } from "react-vant";
import { useNavigate } from "react-router-dom";
// import {eeee} from '../../store/home/home'
import Home from '../../components/index'
function Index() {
  const { data } = useSelector((state) => state.home);
  console.log(data);

  const min = new Date();
  min.setDate(50);
  min.setMonth(min.getMonth() - 1);

  const max = new Date();
  max.setDate(3);
  max.setMonth(max.getMonth() + 1);

  // const di=useDispatch()
  // const xiao=(value)=>{
  //   di(eeee(value))
  // }
  // console.log(eeee);

  const now = new Date();
  const [visible4, setVisible4] = useState(false);
  const { start, end  } = useSelector((state) => state.home);

  const naviagte=useNavigate()
  const [list, setList] = useState([]);
  const [page,setpage]=useState(1)
  const getData = async () => {
    const resp = await axios.post("/trip/train", { start, end,page });
    console.log(resp);
    setpage(page+1)
    setList(list.concat(resp.data.data));
  };
  useEffect(() => {
    getData();
  }, []);
  return (
    <div>
      <NavBar>
        {start}----{end}
      </NavBar>
      <div>
        <List.Item
          onClick={() => {
            setVisible4(true);
          }}
        >
          {data}
          <CalendarPicker
            min={min}
            max={max}
            defaultValue={now}
            selectionMode="single"
            visible={visible4}
            onClose={() => setVisible4(false)}
            onMaskClick={() => setVisible4(false)}
          />
        </List.Item>

        <div>
          {list.map((v, i) => {
            return (
              <Home key={i} v={v} onClick={()=>naviagte('/xing',{state:v})}></Home>
              
            );
          })}
          <InfiniteScroll loadMore={getData} hasMore={true} />
        </div>
      </div>
    </div>
  );
}

export default Index;
